﻿using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using QuanLyTuyenSinh.Base;
using QuanLyTuyenSinh.DataLayer;

namespace QuanLyTuyenSinh.BussinessLayer
{
    public class Zone
    {
        private readonly DataConfig dataConfig;
        private DataTable dtTable;

        public Zone()
        {
            dataConfig = new DataConfig(frmLoading.Servername, frmLoading.UserName, frmLoading.Pass);
        }

        public int Id { get; set; }
        public string ZoneDisplay { get; set; }
        public string ZoneName { get; set; }
        public decimal ZoneNumber { get; set; }


        public int Insert(Zone obj)
        {
            int result = 0;
            string sql = string.Format("INSERT INTO Zone(ZoneDisplay,ZoneName,ZoneNumber) values (N'{0}', N'{1}', '{2}')", obj.ZoneDisplay, obj.ZoneName, obj.ZoneNumber);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Update(Zone obj)
        {
            int result = 0;
            string sql = string.Format("UPDATE Zone SET ZoneDisplay=N'{0}',ZoneName= N'{1}', ZoneNumber='{2}' Where Id=N'{3}'", obj.ZoneDisplay, obj.ZoneName, obj.ZoneNumber, obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }

        public int Delete(Zone obj)
        {
            int result = 0;
            string sql = string.Format("DELETE Zone Where id= N'{0}'", obj.Id);
            try
            {
                result = dataConfig.ExecuteNoneQuery(sql);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return result;
        }
    }
}